<?php
abstract class BaseForm extends sfForm {
    public function setup() {
        // Unset needless widgets
        unset($this['deleted_at'], $this['created_at'], $this['updated_at']);

        // Get form formatter
        $formatter = $this->widgetSchema->getFormFormatter();

        // Set form formatter values
        $formatter->setRowFormat("%label%%help%\n<br class=\"nobr\">\n%field%\n%error%<br class=\"clear\">\n%hidden_fields%\n");
        $formatter->setHelpFormat('%help%');
        $formatter->setErrorRowFormat("<tr><td colspan=\"2\">\n%errors%</td></tr>\n");
        $formatter->setErrorListFormatInARow("<div class=\"error\">%errors%</div>\n");
        $formatter->setErrorRowFormatInARow("%error%");
        //$formatter->setNamedErrorRowFormatInARow(" <li>%name%: %error%</li>\n");
        $formatter->setDecoratorFormat("<div>\n %content%</div>");

        $this->setStarForRequiredFileds();
        $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('catalogue');
    }
    
    public function setStarForRequiredFileds() {
        $helpFormat = '<div class="required">%s</div>';
        foreach ($this->widgetSchema->getPositions() as $widget) {
            $this->validatorSchema[$widget]->getOption('required') === true ?
                $this->widgetSchema->setHelp($widget, sprintf($helpFormat, '*')) :
                $this->widgetSchema->setHelp($widget, sprintf($helpFormat, '&nbsp;'));
        }
    }
}
